/*
//2009/07/18 17:44:07
//2009/07/19 16:23:03, Modified.
#include<iostream>
#include<vector>
#include<string>

using namespace std;
// To record the length of the triangle's bottom-right point sited on (x,y), unfold times;
//int record[50][50][2501];
struct rec
{
    int unfold;		// The times of unfold;
    int size;			// The size of the triangle;
}record[50][50];

class UnfoldingTriangles
{
public:
    int solve(vector <string> grid, int unfoldLimit)
    {
        rows = grid.size();
        columns = grid[0].size();
        int result = 0;
        bool flag = Init(rows, columns, grid);
        if (flag == false) return -1;
        for (int i =1; i<rows; i++)
        {
            for (int j=1; j< columns; j++)
            {
				if(Check(i,j,grid) == false)
				{
					if(grid[i][j] == '/')
					{
						record[i][j].size = 1;
					}
					else
					{
						record[i][j].size = 0;
					}
					record[i][j].unfold = 0;
					continue;
				}
                if (grid[i][j] == '.')
                {
                    record[i][j].size = 0;
                    record[i][j].unfold = 0;
                }
                else if (grid[i][j] == '#')
                {
                    if (record[i-1][j].size == 1 && record[i][j-1].size == 1)
                    {
                        record[i][j].size = 2;
                        record[i][j].unfold = min(record[i-1][j].unfold, record[i][j-1].unfold);
                    }
                    else if ((record[i-1][j].size < 2) || (record[i][j-1].size < 2))
                    {
                        record[i][j].size = 0;
                        record[i][j].unfold = 0;
                    }
                    else
                    {
                        if (record[i-1][j].size > record[i][j-1].size)
                        {
                            record[i][j].size = record[i-1][j].size;
                            record[i][j].unfold = record[i-1][j].unfold;
                        }
                        else if (record[i-1][j].size == record[i][j-1].size)
                        {
                            record[i][j].size = record[i-1][j].size;
                            record[i][j].unfold = min(record[i-1][j].unfold, record[i][j-1].unfold);
                        }
                        else
                        {
                            record[i][j].size = record[i][j-1].size;
                            record[i][j].unfold = record[i][j-1].unfold;
                        }
                    }
                }
                else
                {
                    if (record[i-1][j].size == 1 || record[i][j-1].size == 1)
                    {
                        record[i][j].size = 2;
                        record[i][j].unfold = min(record[i-1][j].unfold, record[i][j-1].unfold)>=unfoldLimit? unfoldLimit: min(record[i-1][j].unfold, record[i][j-1].unfold)+1;
                    }
                    else if ((record[i-1][j].size <= 1) || (record[i][j-1].size <= 1))
                    {
                        record[i][j].size = 1;
                        record[i][j].unfold = 0;
                    }
                    else
                    {
                        if (min(record[i-1][j].unfold,record[i][j-1].unfold) < unfoldLimit)
                        {
                            if (record[i-1][j].size > record[i][j-1].size)
                            {
                                record[i][j].size = record[i-1][j].size + 1;
                                record[i][j].unfold = record[i-1][j].unfold + 1;
                            }
                            else if (record[i-1][j].size == record[i][j-1].size)
                            {
                                record[i][j].size = record[i-1][j].size + 1;
                                record[i][j].unfold = min(record[i-1][j].unfold, record[i][j-1].unfold) + 1;
                            }
                            else
                            {
                                record[i][j].size = record[i][j-1].size + 1;
                                record[i][j].unfold = record[i][j-1].unfold + 1;
                            }
                        }
                        else
                        {
                            record[i][j].size = 1;
                            record[i][j].unfold =0;
                        }
                    }
                }
            }
        }
        for (int i=0; i<rows; i++)
        {
            for (int j=0;j<columns;j++)
            {
                result = max(result, record[i][j].size);
            }
        }
        return (result*(result+1)/2);
    }

private:
    int rows;
    int columns;
    bool Init(int rows, int columns, vector<string> &grid)
    {
        bool flag = false;
        //memset(record, 0, sizeof(record));
        for (int i=0;i<rows;i++)
        {
            for (int j=0;j<columns;j++)
            {
                record[i][j].unfold = 0;
                record[i][j].size = 0;
            }
        }
        for (int i=0;i< rows; i++)
        {
            if (grid[i][0] == '/')
            {
                record[i][0].size = 1;
                record[i][0].unfold =1;
                flag = true;
            }
        }
        for (int j=0; j< columns; j++)
        {
            if (grid[0][j] == '/')
            {
                record[0][j].size = 1;
                record[0][j].unfold =1;
                flag = true;
            }
        }
        return flag;
    }

	bool Check(int r, int c, vector<string> &grid)
	{
		if(r < rows-1)
		{
			for(int i =0; i<record[r][c].size; i++)
			{
				if(grid[r+1][c-i] == '#')
				{
					return false;
				}
			}
		}
		if(c < columns-1)
		{
			for(int i=0; i<record[r][c].size; i++)
			{
				if(grid[r-i][c+1] == '#')
				{
					return false;
				}
			}
		}
		return true;
	}

};
*/
//2009/07/19 19:41:39
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class UnfoldingTriangles
{
public:
    int solve(vector <string> grid, int unfoldLimit)
    {
        int ans=-1;
        int fold=0;

        rows=grid.size();
        columns=grid[0].size();

        for (int i=0; i<rows; ++i)
        {
            for (int j=0; j<columns; ++j)
            {
                for (int s=1; s<=min(i+1,j+1); ++s)
                {
                    fold=unfoldables(i,j,s,grid);
                    if (fold<=unfoldLimit)
                    {
                        ans=max(ans, (1+s)*s/2);
                    }
                }
            }
        }
        return ans;
    }

private:
    int rows;
    int columns;

    int unfoldables(int x, int y, int n, vector <string> &grid)
    {
        int ans=0;
        if (x<(rows-1)) //Check bottom border
        {
            for (int i=0; i<n; ++i)
            {
                if (grid[x+1][y-i]=='#')
                {
                    return 50000;
                }
            }
        }
        if (y<(columns-1)) //Check right border
        {
            for (int i=0; i<n; ++i)
            {
                if (grid[x-i][y+1]=='#')
                {
                    return 50000;
                }
            }
        }
        for (int i=0; i<n; ++i)
        {
            if (grid[x+1-n+i][y-i]!='/')
            {
                return 50000;
            }
        }
        for (int j=0; j<(n-1); ++j)
        {
            for (int i=0; (i+j)<(n-1); ++i)
            {
                if (grid[x-j][y-i]=='.')
                {
                    return 50000;
                }
                if (grid[x-j][y-i]=='/')
                {
                    ++ans;
                }
            }
        }
        return ans;
    }
};
